import request from '@/http';
import axios from 'axios';
import { LoginParams, QQInfo, RegisterParams } from './types';

// 获取用户信息
export function getUserInfo(token: string) {
    return request.get(`/getUserInfo/${token}`)
}

// 登录
export function login(data: LoginParams) {
    return request.post('/login', data)
}

// 注册
export function register(data: RegisterParams) {
    return request.post('/register', data)
}

// 上传文件
export function upload(data: any) {
    return request.post('/upload', data, {
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    })
}

// 获取ip
export function getIp() {
    return axios.get('https://api.ipify.org/')
}

// 根据ip获取位置信息
export function getPositionByIp<T>(ip: any): Promise<T | null> {
    return request.get(`/getPositionByIp/${ip}`)
}

// 发送邮件验证码
export function sendEmailVerify(toEmail: string): Promise<any> {
    return request.post('/sendEmailVerify/:' + toEmail);
}

// 获取qq用户信息
export function getQQInfo(qq: string): Promise<any> {
    if (!qq) return;
    return axios.get('https://api.kit9.cn/api/qq_material/api.php?qq=' + qq)
}
